package com.topisv.tms.entity;

import java.util.List;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.hibernate.validator.constraints.NotBlank;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
@Table(name = "tbl_function")
public class Function extends IdEntity {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String showname;
	private short restype;
	@NotNull
	private String urlprefix;
	@NotNull
	private String viewurl;
	private String status;
	private Function function;
	private List<Function> childMenu;
	
	private List<Permission> permissions;
	
	private Integer idx;

	public Integer getIdx() {
		return idx;
	}

	public void setIdx(Integer idx) {
		this.idx = idx;
	}

	public Function() {
	}

	public Function(Long id) {
		this.id = id;
	}
	
	public String getShowname() {
		return showname;
	}

	public void setShowname(String showname) {
		this.showname = showname;
	}

	public short getRestype() {
		return restype;
	}

	public void setRestype(short restype) {
		this.restype = restype;
	}
	@NotBlank
	public String getUrlprefix() {
		return urlprefix;
	}
	@NotBlank
	public void setUrlprefix(String urlprefix) {
		this.urlprefix = urlprefix;
	}

	public String getViewurl() {
		return viewurl;
	}

	public void setViewurl(String viewurl) {
		this.viewurl = viewurl;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}
	@ManyToOne
	@JoinColumn(name = "parent_id")
	public Function getFunction() {
		return function;
	}

	public void setFunction(Function function) {
		this.function = function;
	}
	@Transient
	@JsonIgnore
	public List<Function> getChildMenu() {
		return childMenu;
	}

	public void setChildMenu(List<Function> childMenu) {
		this.childMenu = childMenu;
	}
	@Transient
	@JsonIgnore
	public List<Permission> getPermissions() {
		return permissions;
	}

	public void setPermissions(List<Permission> permissions) {
		this.permissions = permissions;
	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}
}